﻿using AutoMapper;
using B.S.BsicData.Api.Read.Application.Command;
using B.S.BsicData.Domain;
using B.S.BsicData.ErrorCode.Entity;
using B.S.BsicData.Infartrans;
using MediatR;

namespace B.S.BsicData.Api.Read.Application.CommandHandler
{
    public class QueryDepentmentCommandHandler : IRequestHandler<QueryDepentmentCommand, ApiPaging<DementperModel>>
    {
        private readonly IBaseReository<DementperModel> depRepo;
        private readonly IMapper mapper;

        public QueryDepentmentCommandHandler(IBaseReository<DementperModel> depRepo, IMapper mapper)
        {
            this.depRepo = depRepo;
            this.mapper = mapper;
        }

        public async Task<ApiPaging<DementperModel>> Handle(QueryDepentmentCommand request, CancellationToken cancellationToken)
        {
            ApiPaging<DementperModel> result = new ApiPaging<DementperModel>();
            var str = depRepo.GetAll().ToList();
            if (str != null)
            {
                result.Code = ApiENums.成功;
                result.Message = "成功";
                result.list= str;
            }
            else
            {
                result.Code = ApiENums.失败;
                result.Message = "失败";
            }
            return await Task.FromResult(result);

        }
    }
}
